package com.linln.admin.system.controller;

import com.linln.common.utils.ResultVoUtil;
import com.linln.common.utils.SpringContextUtil;
import com.linln.common.vo.ResultVo;
import com.linln.component.actionLog.action.UserAction;
import com.linln.component.actionLog.annotation.ActionLog;
import com.linln.component.excel.ExcelUtil;
import com.linln.modules.system.domain.*;
import com.linln.modules.system.repository.RPatientBaseInfoRepository;
import com.linln.modules.system.repository.UserRepository;
import com.linln.modules.system.service.RPatientService;
import com.linln.modules.system.service.UserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.net.ssl.HttpsURLConnection;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Date;
import java.sql.Timestamp;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;

@Controller
@RequestMapping("/raredisease/patient")
public class RareDiseasePatientController {

    @Autowired
    private RPatientService rPatientService;

    private static final Logger logger = LoggerFactory.getLogger(RareDiseasePatientController.class);

    /**
     * 列表页面
     */
    @GetMapping("/index")
    @RequiresPermissions("raredisease:patient:index")
    public String index(Model model, PatientBaseInfoEntity pbe) {
        // 创建匹配器，进行动态查询匹配
        ExampleMatcher matcher = ExampleMatcher.matching()
                                 .withMatcher("xm" ,ExampleMatcher.GenericPropertyMatchers.contains());//全部模糊查询，即%{address}%;

        // 获取日志列表
        Example<PatientBaseInfoEntity> example = Example.of(pbe, matcher);

        Page<PatientBaseInfoEntity> plist = rPatientService.getPagePatientBaseList(example);

//        // 封装数据
        model.addAttribute("list", plist.getContent());
        model.addAttribute("page", plist);
//        model.addAttribute("dept", user.getDept());
        return "/raredisease/patient/index";
    }

    @PostMapping("/save")
    @RequiresPermissions({"raredisease:patient:add","raredisease:patient:edit"})
    @ResponseBody
    public ResultVo toSave(HttpServletRequest request){

        String tempstring=null;
        String bah = null;
        SimpleDateFormat Dateformatter = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat DateTimeformatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        java.sql.Date dayDateSql = null;
        java.sql.Date outdate = null;
        //患者基本信息
        PatientBaseInfoEntity patientBaseInfoEntity = null;
        //临床信息
        PatientClinicalInformationEntity patientClinicalInformationEntity = null;
        //出生情况
        PatientBirthSituationEntity patientBirthSituationEntity = null;
        //父母血亲
        PatientParentsSituationEntity patientParentsSituationEntity = null;
        //费用信息
        PatientCostInformationEntity patientCostInformationEntity = null;
        //个人情况
        PatientPersonalSituationEntity patientPersonalSituationEntity = null;
        //患者病案首页费用信息
        PatientBaCostInformationEntity patientBaCostInformationEntity = null;

        //得到患者ID
        tempstring = request.getParameter("patientid");
        if (tempstring != null && tempstring.equals("")==false){//根据患者ID查找患者
            patientBaseInfoEntity = rPatientService.getPatientBaseInfoByid(Integer.parseInt(tempstring));
            if (patientBaseInfoEntity==null){
                logger.error("保存患者时，查询患者失败");
                return ResultVoUtil.error("查询患者失败");
            }
        }else{//根据患者病案号和出院日期查找患者
            String PatientBah = request.getParameter("bah");
            tempstring = request.getParameter("csrq");
            if(tempstring != null && tempstring.equals("") == false){
                dayDateSql = new java.sql.Date(Dateformatter.parse(tempstring,new ParsePosition(0)).getTime());
            }
            patientBaseInfoEntity = rPatientService.getPatientBaseInfoByBAHAndCyrq(PatientBah,dayDateSql);
        }

        if(patientBaseInfoEntity == null){//初始化患者
            patientBaseInfoEntity = new PatientBaseInfoEntity();
            patientClinicalInformationEntity = new PatientClinicalInformationEntity();
            patientBirthSituationEntity = new PatientBirthSituationEntity();
            patientParentsSituationEntity = new PatientParentsSituationEntity();
            patientCostInformationEntity = new PatientCostInformationEntity();
            patientPersonalSituationEntity = new PatientPersonalSituationEntity();
            patientBaCostInformationEntity = new PatientBaCostInformationEntity();
        }else{//根据患者病案号和出院日期，查找患者其他信息
            String patientbah = patientBaseInfoEntity.getBah();
            patientClinicalInformationEntity = rPatientService.getPatientClinicalInfoByBAH(patientbah,patientBaseInfoEntity.getCyrq());
            if(patientClinicalInformationEntity == null){
                patientClinicalInformationEntity = new PatientClinicalInformationEntity();
            }
            patientBirthSituationEntity = rPatientService.getPatientBirthInfoByBAH(patientbah,patientBaseInfoEntity.getCyrq());
            if(patientBirthSituationEntity == null){
                patientBirthSituationEntity = new PatientBirthSituationEntity();
            }
            patientParentsSituationEntity = rPatientService.getPatientParentsInfoByBAH(patientbah,patientBaseInfoEntity.getCyrq());
            if(patientParentsSituationEntity == null){
                patientParentsSituationEntity = new PatientParentsSituationEntity();
            }
            patientCostInformationEntity = rPatientService.getPatientCostInfoByBAH(patientbah,patientBaseInfoEntity.getCyrq());
            if(patientCostInformationEntity == null){
                patientCostInformationEntity = new PatientCostInformationEntity();
            }
            patientPersonalSituationEntity = rPatientService.getPatientPersonalInfoByBAH(patientbah,patientBaseInfoEntity.getCyrq());
            if(patientPersonalSituationEntity == null){
                patientPersonalSituationEntity = new PatientPersonalSituationEntity();
            }
            patientBaCostInformationEntity = rPatientService.getPatientBaCostInformationByBAHAndCyrq(Integer.valueOf(patientbah),patientBaseInfoEntity.getCyrq());
            if(patientBaCostInformationEntity == null){
                patientBaCostInformationEntity = new PatientBaCostInformationEntity();
            }
        }
        //患者基本信息
        //病案号
        bah = request.getParameter("bah");
        patientBaseInfoEntity.setBah(bah);
        //年限
        tempstring = request.getParameter("nx");
        patientBaseInfoEntity.setNx(tempstring);
        //姓名
        tempstring = request.getParameter("xm");
        patientBaseInfoEntity.setXm(tempstring);

        //性别编码
        tempstring = request.getParameter("xbbm");
        patientBaseInfoEntity.setXbbm(tempstring);

        //性别
        if(tempstring.equals("1")==true){
            patientBaseInfoEntity.setXb("男");
        }else if(tempstring.equals("2")==true){
            patientBaseInfoEntity.setXb("女");
        }else{
            patientBaseInfoEntity.setXb("不详");
        }
        //民族
        tempstring = request.getParameter("mz");
        patientBaseInfoEntity.setMz(tempstring);
        //民族编码
        tempstring = request.getParameter("mzbm");
        patientBaseInfoEntity.setMzbm(tempstring);
        //年龄
        tempstring = request.getParameter("nl");
        patientBaseInfoEntity.setNl(tempstring);
        //出生日期
        tempstring = request.getParameter("csrq");
        if(tempstring != null && tempstring.equals("") == false){
            dayDateSql = new java.sql.Date(Dateformatter.parse(tempstring,new ParsePosition(0)).getTime());
            patientBaseInfoEntity.setCsrq(dayDateSql);
        }
        //身份证号
        tempstring = request.getParameter("sfzh");
        patientBaseInfoEntity.setSfzh(tempstring);
        //户口所在地
        tempstring = request.getParameter("hkszd");
        patientBaseInfoEntity.setHkszd(tempstring);
        //出生地
        tempstring = request.getParameter("csd");
        patientBaseInfoEntity.setCsd(tempstring);
        //现住址
        tempstring = request.getParameter("xzz");
        patientBaseInfoEntity.setXzz(tempstring);
        //生存情况
        tempstring = request.getParameter("scqk");
        patientBaseInfoEntity.setScqk(tempstring);
        //联系人
        tempstring = request.getParameter("lxr");
        patientBaseInfoEntity.setLxr(tempstring);
        //联系人电话
        tempstring = request.getParameter("lxrdh");
        patientBaseInfoEntity.setLxrdh(tempstring);
        //邮编
        tempstring = request.getParameter("yb");
        patientBaseInfoEntity.setYb(tempstring);

        //入院时间
        tempstring = request.getParameter("ryrq");
        if(tempstring != null && tempstring.equals("") == false){
            dayDateSql = new java.sql.Date(Dateformatter.parse(tempstring,new ParsePosition(0)).getTime());
            patientBaseInfoEntity.setRyrq(dayDateSql);
        }

        //出院时间
        tempstring = request.getParameter("cyrq");
        if(tempstring != null && tempstring.equals("") == false){
            dayDateSql = new java.sql.Date(Dateformatter.parse(tempstring,new ParsePosition(0)).getTime());
            patientBaseInfoEntity.setCyrq(dayDateSql);
            outdate = dayDateSql;
        }
        //离院方式
        tempstring = request.getParameter("lyfs");
        patientBaseInfoEntity.setLyfs(tempstring);
        //死亡时间
        tempstring = request.getParameter("swsj");
        patientBaseInfoEntity.setSwsj(tempstring);
        rPatientService.savePatientBaseInfo(patientBaseInfoEntity);

        //临床信息
        patientClinicalInformationEntity.setBah(bah);
        //发病年龄
        tempstring = request.getParameter("fbnl");
        patientClinicalInformationEntity.setFbnl(tempstring);
        //发病年龄单位
        tempstring = request.getParameter("fbnldw");
        patientClinicalInformationEntity.setFbnldw(tempstring);
        //首次就医(非罕见病原因就医)
        tempstring = request.getParameter("scjysj");
        if(tempstring != null && tempstring.equals("") == false){
            dayDateSql = new java.sql.Date(Dateformatter.parse(tempstring,new ParsePosition(0)).getTime());
            patientClinicalInformationEntity.setScjysj(dayDateSql);
        }
        //首次(罕见病)发病时间
        tempstring = request.getParameter("scfbsj");
        if(tempstring != null && tempstring.equals("") == false){
            dayDateSql = new java.sql.Date(Dateformatter.parse(tempstring,new ParsePosition(0)).getTime());
            patientClinicalInformationEntity.setScfbsj(dayDateSql);
        }
        //是否首次诊断
        tempstring = request.getParameter("sfsjzd");
        patientClinicalInformationEntity.setSfsjzd(tempstring);

        //首次诊断本市外地
        tempstring = request.getParameter("sczdyystate");
        patientClinicalInformationEntity.setSczdyystate(tempstring);
        //首次诊断医院
        tempstring = request.getParameter("sczdyy");
        patientClinicalInformationEntity.setSczdyy(tempstring);
        //接诊机构
        tempstring = request.getParameter("jzjg");
        patientClinicalInformationEntity.setJzjg(tempstring);
        //首次诊断医院
        tempstring = request.getParameter("sczdyy");
        patientClinicalInformationEntity.setSczdyy(tempstring);
        //就医主诉
        tempstring = request.getParameter("jyzs");
        patientClinicalInformationEntity.setJyzs(tempstring);
        //主要症状
        tempstring = request.getParameter("zyzz");
        patientClinicalInformationEntity.setZyzz(tempstring);
        //重要体征
        tempstring = request.getParameter("zytz");
        patientClinicalInformationEntity.setZytz(tempstring);
        //酶学检查
        tempstring = request.getParameter("mxjc");
        patientClinicalInformationEntity.setMxjc(tempstring);
        //基因检查
        tempstring = request.getParameter("jyjc");
        patientClinicalInformationEntity.setJyjc(tempstring);
//        //化验检查结果
//        tempstring = request.getParameter("hyjcjg");
//        patientClinicalInformationEntity.setHyjcjg(tempstring);
        //实验室检查(血、尿、便、常规、其他、生化、病理报告、基因报告)
//        tempstring = request.getParameter("sysjc");
//        patientClinicalInformationEntity.setSysjc(tempstring)
        //血常规
        tempstring = request.getParameter("xcgjcjg");
        patientClinicalInformationEntity.setXcgjcjg(tempstring);
        //尿常规
        tempstring = request.getParameter("ncgjcjg");
        patientClinicalInformationEntity.setNcgjcjg(tempstring);
        //血生化
        tempstring = request.getParameter("xxhjcjg");
        patientClinicalInformationEntity.setXxhjcjg(tempstring);
        //病理检查
        tempstring = request.getParameter("bljcjg");
        patientClinicalInformationEntity.setBljcjg(tempstring);
        //基因检查
        tempstring = request.getParameter("jyjcjg");
        patientClinicalInformationEntity.setJyjcjg(tempstring);
        //其他检查结果
        tempstring = request.getParameter("qtjcjg");
        patientClinicalInformationEntity.setQtjcjg(tempstring);

         //影像(x-ray、B超、CT、核磁、其他)
//        tempstring = request.getParameter("yx");
//        patientClinicalInformationEntity.setYx(tempstring);
        //x-ray
        tempstring = request.getParameter("xxyxjg");
        patientClinicalInformationEntity.setXxyxjg(tempstring);
        //B超
        tempstring = request.getParameter("bcyxjg");
        patientClinicalInformationEntity.setBcyxjg(tempstring);
        //CT
        tempstring = request.getParameter("ctyxjg");
        patientClinicalInformationEntity.setCtyxjg(tempstring);
        //核磁
        tempstring = request.getParameter("hcyxjg");
        patientClinicalInformationEntity.setHcyxjg(tempstring);
        //其他影像结果
        tempstring = request.getParameter("qtyxjg");
        patientClinicalInformationEntity.setQtyxjg(tempstring);

        //诊断时间
        tempstring = request.getParameter("zdsj");
        if(tempstring != null && tempstring.equals("") == false){
            dayDateSql = new java.sql.Date(Dateformatter.parse(tempstring,new ParsePosition(0)).getTime());
            patientClinicalInformationEntity.setZdsj(dayDateSql);
        }
        //诊断类型
        tempstring = request.getParameter("zdlx");
        patientClinicalInformationEntity.setZdlx(tempstring);
        //疑诊诊断
//        tempstring = request.getParameter("yszd_icd10");
//        patientClinicalInformationEntity.setYszdIcd10(tempstring);
        //疑诊诊断名称
        tempstring = request.getParameter("yszd");
        patientClinicalInformationEntity.setYszd(tempstring);
        //确诊诊断
//        tempstring = request.getParameter("qzzd_icd10");
//        patientClinicalInformationEntity.setQzzdIcd10(tempstring);
        //确诊诊断名称
        tempstring = request.getParameter("qzzd");
        patientClinicalInformationEntity.setQzzd(tempstring);
        //疾病编码
        tempstring = request.getParameter("jbzd_icd10");
        patientClinicalInformationEntity.setJbzdIcd10(tempstring);
        //疾病诊断名称
        tempstring = request.getParameter("jbzdmc");
        patientClinicalInformationEntity.setJbzdmc(tempstring);
        //其他诊断
//        tempstring = request.getParameter("sub_diagnosis_1_icd10");
//        patientClinicalInformationEntity.setSubDiagnosis1Icd10(tempstring);
        //其他诊断名称1
        tempstring = request.getParameter("sub_diagnosis_1");
        patientClinicalInformationEntity.setSubDiagnosis1(tempstring);
        //其他诊断名称2
        tempstring = request.getParameter("sub_diagnosis_2");
        patientClinicalInformationEntity.setSubDiagnosis2(tempstring);
        //其他诊断名称3
        tempstring = request.getParameter("sub_diagnosis_3");
        patientClinicalInformationEntity.setSubDiagnosis3(tempstring);
        //确诊依据
        tempstring = request.getParameter("qzyj");
        patientClinicalInformationEntity.setQzyj(tempstring);
        //诊断方法
        tempstring = request.getParameter("zdff");
        patientClinicalInformationEntity.setZdff(tempstring);
        //本次诊断医师
        tempstring = request.getParameter("bczdys");
        patientClinicalInformationEntity.setBczdys(tempstring);
        //是否转诊
        tempstring = request.getParameter("sfzz");
        patientClinicalInformationEntity.setSfzz(tempstring);
        //启动特意性治疗时间
        tempstring = request.getParameter("qdtyxzlsj");
        if(tempstring != null && tempstring.equals("") == false){
            dayDateSql = new java.sql.Date(Dateformatter.parse(tempstring,new ParsePosition(0)).getTime());
            patientClinicalInformationEntity.setQdtyxzlsj(dayDateSql);
        }
        //治疗方案
        tempstring = request.getParameter("zl");
        patientClinicalInformationEntity.setZl(tempstring);
        //特异性治疗方式
        tempstring = request.getParameter("tyxzlfs");
        patientClinicalInformationEntity.setTyxzlfs(tempstring);
        //非特异性治疗方式
        tempstring = request.getParameter("ftyxzlfs");
        patientClinicalInformationEntity.setFtyxzlfs(tempstring);

        patientClinicalInformationEntity.setCyrq(outdate);

        rPatientService.savePatientClinicalInformation(patientClinicalInformationEntity);

        //出生情况
        patientBirthSituationEntity.setBah(bah);
        //G?P?
        tempstring = request.getParameter("gp");
        patientBirthSituationEntity.setGp(tempstring);
        //母孕期情况
        tempstring = request.getParameter("myqqk");
        patientBirthSituationEntity.setMyqqk(tempstring);
//        //围产期情况
//        tempstring = request.getParameter("wcqqk");
//        patientBirthSituationEntity.setWcqqk(tempstring);
        //出生情况
        tempstring = request.getParameter("csqk");
        patientBirthSituationEntity.setCsqk(tempstring);
        //生后情况
        tempstring = request.getParameter("shqk");
        patientBirthSituationEntity.setShqk(tempstring);

        patientBirthSituationEntity.setCyrq(outdate);

        rPatientService.savePatientBirthSituation(patientBirthSituationEntity);
        //个人情况
        patientPersonalSituationEntity.setBah(bah);
        //家庭成员人数
        tempstring = request.getParameter("jtcys");
        patientPersonalSituationEntity.setJtcys(tempstring);
        //有无家族史
        tempstring = request.getParameter("ywjzs");
        if(tempstring == null){
            tempstring ="3";
        }
        patientPersonalSituationEntity.setYwjzs(tempstring);
        if (tempstring.equals("1")==true){
            //家族史
            tempstring = request.getParameter("jzs");
            patientPersonalSituationEntity.setJzs(tempstring);
        }else if (tempstring.equals("2")==true){
            //家族史
            patientPersonalSituationEntity.setJzs("");
        }else if (tempstring.equals("3")==true){
            //家族史
            patientPersonalSituationEntity.setJzs("不详");
        }

        //家庭同病种患病人数
        tempstring = request.getParameter("jttbzhbrs");
        patientPersonalSituationEntity.setJttbzhbrs(tempstring);
        //家庭患病成员与患者关系
        tempstring = request.getParameter("jthbcyyhzgx");
        patientPersonalSituationEntity.setJthbcyyhzgx(tempstring);
        //个人史
        tempstring = request.getParameter("grs");
        patientPersonalSituationEntity.setGrs(tempstring);

        patientPersonalSituationEntity.setCyrq(outdate);

        rPatientService.savePatientPersonalSituation(patientPersonalSituationEntity);

        //血亲父母
        patientParentsSituationEntity.setBah(bah);
//        //健康情况
//        tempstring = request.getParameter("jkqk");
//        patientParentsSituationEntity.setJkqk(tempstring);
//        //受教育程度
//        tempstring = request.getParameter("sjycd");
//        patientParentsSituationEntity.setSjycd(tempstring);
//        //是否婚检
//        tempstring = request.getParameter("sfhj");
//        patientParentsSituationEntity.setSfhj(tempstring);
//        //是否孕检
//        tempstring = request.getParameter("sfyj");
//        patientParentsSituationEntity.setSfyj(tempstring);
//        //父母存在疾病
//        tempstring = request.getParameter("fmczjb");
//        patientParentsSituationEntity.setFmczjb(tempstring);

        //父亲年龄
        tempstring = request.getParameter("fqnl");
        patientParentsSituationEntity.setFqnl(tempstring);
        //父亲年龄单位
        tempstring = request.getParameter("fqnldw");
        patientParentsSituationEntity.setFqnldw(tempstring);
        //父亲健康情况
        tempstring = request.getParameter("fqjkqk");
        patientParentsSituationEntity.setFqjkqk(tempstring);
        //父亲存在疾病
        tempstring = request.getParameter("fqczjb");
        patientParentsSituationEntity.setFqczjb(tempstring);
        //父亲是否婚检
        tempstring = request.getParameter("fqhj");
        patientParentsSituationEntity.setFqhj(tempstring);
        //父亲受教育程序
        tempstring = request.getParameter("fqsjycd");
        patientParentsSituationEntity.setFqsjycd(tempstring);

        //母亲年龄
        tempstring = request.getParameter("mqnl");
        patientParentsSituationEntity.setMqnl(tempstring);
        //母亲年龄单位
        tempstring = request.getParameter("mqnldw");
        patientParentsSituationEntity.setMqnldw(tempstring);
        //母亲健康情况
        tempstring = request.getParameter("mqjkqk");
        patientParentsSituationEntity.setMqjkqk(tempstring);
        //母亲存在疾病
        tempstring = request.getParameter("mqczjb");
        patientParentsSituationEntity.setMqczjb(tempstring);
        //母亲是否婚检
        tempstring = request.getParameter("mqhj");
        patientParentsSituationEntity.setMqhj(tempstring);
        //母亲是否孕检
        tempstring = request.getParameter("mqyj");
        patientParentsSituationEntity.setMqyj(tempstring);
        //母亲受教育程序
        tempstring = request.getParameter("mqsjycd");
        patientParentsSituationEntity.setMqsjycd(tempstring);

        //兄健康情况
        tempstring = request.getParameter("xjkqk");
        patientParentsSituationEntity.setXjkqk(tempstring);
        //弟健康情况
        tempstring = request.getParameter("djkqk");
        patientParentsSituationEntity.setDjkqk(tempstring);
        //姐健康情况
        tempstring = request.getParameter("jjkqk");
        patientParentsSituationEntity.setJjkqk(tempstring);
        //妹健康情况
        tempstring = request.getParameter("mjkqk");
        patientParentsSituationEntity.setMjkqk(tempstring);

        patientParentsSituationEntity.setCyrq(outdate);

        rPatientService.savePatientParentsSituation(patientParentsSituationEntity);

        //费用信息
        patientCostInformationEntity.setBah(bah);
        //家庭平均年总收入
        tempstring = request.getParameter("jtpjnzsr");
        patientCostInformationEntity.setJtpjnzsr(tempstring);
        //发病至确诊前的总费用
        tempstring = request.getParameter("fbzqzdzfy");
        patientCostInformationEntity.setFbzqzdzfy(tempstring);
        //确认后的总治疗费用自费占比
        tempstring = request.getParameter("qrhdzzlfyzfzb");
        patientCostInformationEntity.setQrhdzzlfyzfzb(tempstring);
        //发病以来每年额外增加的费用
        tempstring = request.getParameter("fbylmnewzjdfy");
        patientCostInformationEntity.setFbylmnewzjdfy(tempstring);
        //医保类型
        tempstring = request.getParameter("yblx");
        patientCostInformationEntity.setYblx(tempstring);

        patientCostInformationEntity.setCyrq(outdate);

        rPatientService.savePatientCostInformation(patientCostInformationEntity);

        //患者病案首页费用信息
        patientBaCostInformationEntity.setBah(Integer.parseInt(bah));
        patientBaCostInformationEntity.setCyrq(outdate);
        //费用总计
        tempstring = request.getParameter("fyhj");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFyhj(new BigDecimal(tempstring));
        //自付金额
        tempstring = request.getParameter("zfje");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setZfje(new BigDecimal(tempstring));
        //一般医疗服务费
        tempstring = request.getParameter("fy01");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy01(new BigDecimal(tempstring));
        //一般治疗操作费
        tempstring = request.getParameter("fy02");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy02(new BigDecimal(tempstring));
        //护理费
        tempstring = request.getParameter("fy03");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy03(new BigDecimal(tempstring));
        //其他费用
        tempstring = request.getParameter("fy04");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy04(new BigDecimal(tempstring));
        //病理诊断费
        tempstring = request.getParameter("fy05");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy05(new BigDecimal(tempstring));
        //实验室诊断费
        tempstring = request.getParameter("fy06");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy06(new BigDecimal(tempstring));
        //影像学诊断费
        tempstring = request.getParameter("fy07");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy07(new BigDecimal(tempstring));
        //临床诊断项目费
        tempstring = request.getParameter("fy08");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy08(new BigDecimal(tempstring));
        //非手术治疗项目费
        tempstring = request.getParameter("fy09");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy09(new BigDecimal(tempstring));
        //临床物理治疗费
        tempstring = request.getParameter("fy0901");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy0901(new BigDecimal(tempstring));
        //手术治疗费
        tempstring = request.getParameter("fy10");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy10(new BigDecimal(tempstring));
        //麻醉费
        tempstring = request.getParameter("fy1001");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy1001(new BigDecimal(tempstring));
        //手术费
        tempstring = request.getParameter("fy1002");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy1002(new BigDecimal(tempstring));
        //康复费
        tempstring = request.getParameter("fy11");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy11(new BigDecimal(tempstring));
        //中医治疗费
        tempstring = request.getParameter("fy12");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy12(new BigDecimal(tempstring));
        //西药费
        tempstring = request.getParameter("fy13");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy13(new BigDecimal(tempstring));
        //抗菌药费费用
        tempstring = request.getParameter("fy1301");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy1301(new BigDecimal(tempstring));
        //中成药费
        tempstring = request.getParameter("fy14");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy14(new BigDecimal(tempstring));
        //中草药费
        tempstring = request.getParameter("fy15");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy15(new BigDecimal(tempstring));
        //血费
        tempstring = request.getParameter("fy16");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy16(new BigDecimal(tempstring));
        //血蛋白制品费
        tempstring = request.getParameter("fy17");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy17(new BigDecimal(tempstring));
        //球蛋白类制品费
        tempstring = request.getParameter("fy18");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy18(new BigDecimal(tempstring));
        //凝血因子类制品费
        tempstring = request.getParameter("fy19");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy19(new BigDecimal(tempstring));
        //细胞因子类制品费
        tempstring = request.getParameter("fy20");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy20(new BigDecimal(tempstring));
        //检查用一次性医用材料费
        tempstring = request.getParameter("fy21");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy21(new BigDecimal(tempstring));
        //治疗用一次性医用材料费
        tempstring = request.getParameter("fy22");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy22(new BigDecimal(tempstring));
        //手术用一次性医用材料费
        tempstring = request.getParameter("fy23");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy23(new BigDecimal(tempstring));
        //其他费
        tempstring = request.getParameter("fy24");
        if(tempstring==null||tempstring.equals("")){
            tempstring = "0.0";
        }
        patientBaCostInformationEntity.setFy24(new BigDecimal(tempstring));

        rPatientService.savePatientBACostInformation(patientBaCostInformationEntity);
        return ResultVoUtil.SAVE_SUCCESS;
    }

    /**
     * 跳转到添加页面
     */
    @GetMapping("/add")
    @RequiresPermissions("raredisease:patient:add")
    public String toAdd() {
        return "/raredisease/patient/add";
    }

    /**
     * 跳转到编辑页面
     */
    @GetMapping("/edit/{id}")
    @RequiresPermissions("raredisease:patient:edit")
    public String toEdit(@PathVariable("id") Integer patientid, Model model) {
        //患者基本信息
        PatientBaseInfoEntity patientBaseInfoEntity = rPatientService.getPatientBaseInfoByid(patientid);
        //临床信息
        PatientClinicalInformationEntity patientClinicalInformationEntity = rPatientService.getPatientClinicalInfoByBAH(patientBaseInfoEntity.getBah(),patientBaseInfoEntity.getCyrq());
        //出生情况
        PatientBirthSituationEntity patientBirthSituationEntity = rPatientService.getPatientBirthInfoByBAH(patientBaseInfoEntity.getBah(),patientBaseInfoEntity.getCyrq());
        //父母血亲
        PatientParentsSituationEntity patientParentsSituationEntity = rPatientService.getPatientParentsInfoByBAH(patientBaseInfoEntity.getBah(),patientBaseInfoEntity.getCyrq());
        //费用信息
        PatientCostInformationEntity patientCostInformationEntity = rPatientService.getPatientCostInfoByBAH(patientBaseInfoEntity.getBah(),patientBaseInfoEntity.getCyrq());
        //个人情况
        PatientPersonalSituationEntity patientPersonalSituationEntity = rPatientService.getPatientPersonalInfoByBAH(patientBaseInfoEntity.getBah(),patientBaseInfoEntity.getCyrq());

        Integer IBAH = Integer.valueOf(patientBaseInfoEntity.getBah());
        //患者病案首页费用信息
        PatientBaCostInformationEntity patientBaCostInformationEntity = rPatientService.getPatientBaCostInformationByBAHAndCyrq(IBAH,patientBaseInfoEntity.getCyrq());

        //临床信息
        model.addAttribute("patientclinicalinfo",patientClinicalInformationEntity);
        //出生情况
        model.addAttribute("patientbirthinfo",patientBirthSituationEntity);
        //父母血亲
        model.addAttribute("patientparentsinfo",patientParentsSituationEntity);
        //费用信息
        model.addAttribute("patientcostinfo",patientCostInformationEntity);
        //个人情况
        model.addAttribute("patientpersonalinfo",patientPersonalSituationEntity);
        //患者基本信息
        model.addAttribute("patientbaseinfo", patientBaseInfoEntity);
        //患者病案首页费用信息
        model.addAttribute("patientbacostinfo",patientBaCostInformationEntity);

        return "/raredisease/patient/add";
    }

    /**
     * 导出用户数据
     */
    @GetMapping("/export")
    @RequiresPermissions("raredisease:patient:export")
    @ResponseBody
    public void exportExcel() {
        RPatientBaseInfoRepository rPatientBaseInfoRepository = SpringContextUtil.getBean(RPatientBaseInfoRepository.class);
        ExcelUtil.exportExcel(PatientBaseInfoEntity.class, rPatientBaseInfoRepository.findAll());
    }

    /**
     * 跳转到详细页面
     */
    @GetMapping("/detail/{id}")
    @RequiresPermissions("raredisease:patient:detail")
    public String toDetail(@PathVariable("id") Integer patientid, Model model) {
        //患者基本信息
        PatientBaseInfoEntity patientBaseInfoEntity = rPatientService.getPatientBaseInfoByid(patientid);

        //临床信息
        PatientClinicalInformationEntity patientClinicalInformationEntity = rPatientService.getPatientClinicalInfoByBAH(patientBaseInfoEntity.getBah(),patientBaseInfoEntity.getCyrq());
        //出生情况
        PatientBirthSituationEntity patientBirthSituationEntity = rPatientService.getPatientBirthInfoByBAH(patientBaseInfoEntity.getBah(),patientBaseInfoEntity.getCyrq());
        //父母血亲
        PatientParentsSituationEntity patientParentsSituationEntity = rPatientService.getPatientParentsInfoByBAH(patientBaseInfoEntity.getBah(),patientBaseInfoEntity.getCyrq());
        //费用信息
        PatientCostInformationEntity patientCostInformationEntity = rPatientService.getPatientCostInfoByBAH(patientBaseInfoEntity.getBah(),patientBaseInfoEntity.getCyrq());
        //个人情况
        PatientPersonalSituationEntity patientPersonalSituationEntity = rPatientService.getPatientPersonalInfoByBAH(patientBaseInfoEntity.getBah(),patientBaseInfoEntity.getCyrq());

        Integer IBAH = Integer.valueOf(patientBaseInfoEntity.getBah());
        //患者病案首页费用信息
        PatientBaCostInformationEntity patientBaCostInformationEntity = rPatientService.getPatientBaCostInformationByBAHAndCyrq(IBAH,patientBaseInfoEntity.getCyrq());


        //临床信息
        model.addAttribute("patientclinicalinfo",patientClinicalInformationEntity);
        //出生情况
        model.addAttribute("patientbirthinfo",patientBirthSituationEntity);
        //父母血亲
        model.addAttribute("patientparentsinfo",patientParentsSituationEntity);
        //费用信息
        model.addAttribute("patientcostinfo",patientCostInformationEntity);
        //个人情况
        model.addAttribute("patientpersonalinfo",patientPersonalSituationEntity);
        //患者基本信息
        model.addAttribute("patientbaseinfo", patientBaseInfoEntity);
        //患者病案首页费用信息
        model.addAttribute("patientbacostinfo",patientBaCostInformationEntity);

        return "/raredisease/patient/detail";
    }
}
